<?php

namespace App\Console\Commands;

use App\Events\UserLoanRequestQueryResultEvent;
use App\Facades\SamLogFacade;
use App\Models\UserLoanRequest;
use Illuminate\Console\Command;

class PushLoanRequestResult extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'push:loan_request_result';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $requests = UserLoanRequest::where('status',UserLoanRequest::STATUS_APPLY)
            ->where('retry','<>',UserLoanRequest::RETRY_YES)
            ->get();
        $requests->map(function($item){
            event(new UserLoanRequestQueryResultEvent($item->credit_id));
            SamLogFacade::debug("授信记录【{$item->id}】进入查询结果事件");
        });
    }
}
